package com.oscar.ehome.view.pageview.adapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.oscar.ehome.R;
import com.oscar.ehome.base.C;
import com.oscar.ehome.bean.pagebean.StudyBean;
import com.oscar.ehome.bean.pagebean.xuexifenleiBean;
import com.oscar.ehome.bean.setbean.LearnHistoryBean;
import com.oscar.ehome.provider.gildeimage.GildeUtils;

import java.util.List;

/**
 * Created by juxing
 * author: MengWanhe
 * date: On 2017/12/11
 */

public class StudyGuoDu_Adapter extends BaseAdapter {


    private List<xuexifenleiBean.wenjian> list;
    private LayoutInflater mInflater;
    private Context mContext = null;

    int size = 0;

    public StudyGuoDu_Adapter(Context context, List<xuexifenleiBean.wenjian> list) {
        this.mContext = context;
        this.list = list;

        mInflater = LayoutInflater.from(context);
    }

    public void setLists(List<xuexifenleiBean.wenjian> list) {
        this.list = list;

        notifyDataSetChanged();
    }


    @Override
    public int getCount() {

        size = list.size();
        return size;
    }

    @Override
    public Object getItem(int position) {

        return list.get(position);

    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        StudyGuoDu_Adapter.ViewHolder holder;
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.xuexiguoduitem, null);
            holder = new StudyGuoDu_Adapter.ViewHolder();
            holder.study_title = (TextView) convertView.findViewById(R.id.study_title);

            holder.study_img = (ImageView) convertView.findViewById(R.id.study_guodu_img);
            holder.study_number = (TextView) convertView.findViewById(R.id.study_number);
            convertView.setTag(holder); //
        } else {
            holder = (StudyGuoDu_Adapter.ViewHolder) convertView.getTag(); //
        }


        holder.study_title.setText(list.get(position).getTitle());
        holder.study_number.setText("共" + list.get(position).getLearnNum() + "条");
        int num = Integer.parseInt(list.get(position).getLearnNum());
        String importurl = C.qiniu_ip + list.get(position).getImage();
        if (num > 0) {
            GildeUtils.loadUrlImagewenjianyoushuju(importurl, holder.study_img, mContext);
        } else {
            GildeUtils.loadUrlImagewenjianwushuju(importurl, holder.study_img, mContext);
        }

        return convertView;
    }

    class ViewHolder {
        TextView study_title;//标题
        ImageView study_img;//图片
        TextView study_number;//时间

    }

}
